package 公司真题.shopee;

import java.util.Arrays;
import java.util.Scanner;

public class _最小路径和 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String msg = sc.nextLine();
        msg = msg.substring(1, msg.length() - 1);
        String[] msgs = msg.split("]");
        String[] newMsgs = new String[msgs.length];
        for (int i = 0; i < msgs.length; i++) {
            newMsgs[i] = msgs[i].replace('[', ' ').replace(',', ' ').trim();
            System.out.println(newMsgs[i]);
        }
        int n = newMsgs.length;
        int m = (newMsgs[0].length() >> 1) + 1;
        int[][] arr = new int[n][m];
        System.out.println("---------------");
        for (int i = 0; i < arr.length; i++) {
            String[] temp = newMsgs[i].split(" ");
            for (int j = 0; j < arr[0].length; j++) {
                arr[i][j] = Integer.parseInt(temp[j]);
            }
            System.out.println(Arrays.toString(arr[i]));
        }
//        System.out.println(Arrays.toString(msgs));
        int res = minRoundValue(arr);
        System.out.println(res);
    }

    private static int minRoundValue(int[][] arr) {
        if (arr == null || arr.length == 0 || arr[0].length == 0) return 0;
        int[][] dp = new int[arr.length][arr[0].length];
        dp[0][0] = arr[0][0];
        for (int i = 1; i < arr.length; i++) {
            dp[i][0] = arr[i][0] + dp[i - 1][0];
        }
        for (int i = 1; i < arr[0].length; i++) {
            dp[0][i] = arr[0][i] + dp[0][i - 1];
        }

        for (int i = 1; i < arr.length; i++) {
            for (int j = 1; j < arr[0].length; j++) {
                dp[i][j] = arr[i][j] + Math.min(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        return dp[arr.length - 1][arr[0].length - 1];
    }
}
